package com.corange.insuranceinformation.modules.api.controller;

import com.corange.insuranceinformation.common.utils.CacheUtils;
import com.corange.insuranceinformation.common.utils.ResultData;
import com.corange.insuranceinformation.modules.metadata.dto.MetaQueryDTO;
import com.corange.insuranceinformation.modules.metadata.vo.MetaDataVO;
import com.corange.insuranceinformation.modules.metadata.vo.MetaPageVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Title: ApiController
 * @Prject: insurance-information
 * @Package: com.corange.insuranceinformation.modules.api.controller
 * @Description:
 * @author: willinggod
 * @date: 2019/11/1 17:39
 * @version: V1.0
 */
@RestController
@RequestMapping("/api/metadata")
public class ApiController {
    /**
     *  根据元数据代码或者名称模糊查询数据
     * @param metaQueryDTO 元数据查询入参对象
     * @author willinggod
     * @return ResultData
     */
    @PostMapping("/metaDatasQuery")
    public ResultData metaDatasQuery(@Valid@NotNull(message = "入参不能为空") MetaQueryDTO metaQueryDTO){
        //根据关键字模糊查询
        String metaQueryKey=metaQueryDTO.getMetaQueryKey();
        //获取当前页码
        Integer currentPage=null!=metaQueryDTO.getCurrentPage()?metaQueryDTO.getCurrentPage():1;
        //获取每页展示的数量
        Integer pageSize=null!=metaQueryDTO.getPageSize()?metaQueryDTO.getPageSize():10;
        MetaPageVO metaPageVO= CacheUtils.searchMetaDataByKeyNameForPages(metaQueryKey,pageSize,currentPage);
        ResultData resultData=ResultData.ok();
        resultData.put("data",metaPageVO);
        //基于代码或者名称模糊查询
        return resultData;
    }
}

